package ace.cmp.jetcache.config;

import ace.cmp.jetcache.AceSimpleCacheManager;
import com.alicp.jetcache.CacheManager;
import com.alicp.jetcache.anno.support.SpringConfigProvider;
import com.alicp.jetcache.autoconfigure.JetCacheAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author caspar
 * @date 2023/3/9 15:58
 */
@AutoConfigureBefore(JetCacheAutoConfiguration.class)
@Configuration
public class AceJetCacheAutoConfigure {

  @Bean
  @ConditionalOnMissingBean
  public CacheManager cacheManager(SpringConfigProvider springConfigProvider) {
    AceSimpleCacheManager cacheManager = new AceSimpleCacheManager();
    cacheManager.setCacheBuilderTemplate(springConfigProvider.getCacheBuilderTemplate());
    return cacheManager;
  }
}
